<template>
  <div class="order">
    <!-- 地址 -->
    <div class="address" v-if="addressInfo.id">
      <router-link class="item" tag="div" to="/my/address">
        <div class="left">
          <div class="name">{{addressData.name}}</div>
          <div class="moren" v-if="addressData.is_default == 1">默认</div>
        </div>
        <div class="middle">
          <div class="tel">{{addressData.mobile}}</div>
          <div class="info">{{addressData.address}} {{addressData.address_detail}}</div>
        </div>
        <div class="right"></div>
      </router-link>
    </div>
    <router-link tag="div" to="/my/address" class="none" v-else>
      请选择收货地址
    </router-link>
    <!-- 信息 -->
    <div class="info">
      <div class="item">
        <div class="left">商品合计</div>
        <div class="right">￥{{allPrise}}</div>
      </div>
      <div class="item">
        <div class="left">运费</div>
        <div class="right">免运费</div>
      </div>
      <div class="item">
        <div class="left">优惠券</div>
        <div class="right">暂无</div>
      </div>
    </div>
    <!-- 列表 -->
    <div class="list">
      <div class="item" v-for='item in goodsList' :key='item.id'>
        <div class="left">
          <img :src="item.list_pic_url" alt="">
          <div class="info">
            <div class="name">{{item.goods_name}}</div>
            <div class="price">￥{{item.retail_price}}</div>
          </div>
        </div>
        <div class="right">x{{item.number}}</div>
      </div>
    </div>
    <!-- 支付 -->
    <div class="bottom">
      <div class="total">实付 : ￥{{allPrise}}</div>
      <div class="pay" @click="payEvents">支付</div>
    </div>
  </div>
</template>

<script>
import { detailAction } from "@/api/cart";
export default {
  data() {
    return {
      addressData: {}, // 地址数据
      allPrise: "", // 总价
      goodsList: [], // 列表
      addressInfo: "", // stroe存储的地址信息
    };
  },
  // 计算
  computed: {},
  // 创建
  created() {
    this.addressInfo = this.$store.state.addressInfo;
    // 判断存储里是否有地址信息
    if (this.addressInfo.id) {
      this.addressInfo.id = this.$store.state.addressInfo.id;
    } else {
      this.addressInfo.id = "";
    }
    // 订单确认界面数据获取
    detailAction({
      openId: localStorage.getItem("openId"),
      addressId: this.addressInfo.id,
    }).then((res) => {
      // console.log(res);
      this.addressData = res.data.address;
      this.allPrise = res.data.allPrise;
      this.goodsList = res.data.goodsList;
    });
  },
  // 准备
  mounted() {},
  // 方法
  methods: {
    // 支付
    payEvents() {
      this.$toast({
        message: "支付功能暂未开发",
        icon: "none",
      });
    },
  },
};
</script>

<style lang='scss' scoped>
.order {
  // 地址
  .address {
    background: url("http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/address-bg-bd30f2bfeb.png")
      repeat-x;
    padding: 25px 0 15px;
    margin-bottom: 10px;
    background-color: #fff;
    .item {
      padding: 0 10px;
      display: flex;
      align-items: center;
      // 左
      .left {
        width: 50px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        align-self: flex-start;
        .name {
          margin: 12px auto;
        }
        .moren {
          width: 30px;
          height: 15px;
          border: 1px solid #b4282d;
          margin: 5px auto 0;
          color: #b4282d;
          line-height: 15px;
        }
      }
      // 中
      .middle {
        padding: 0 10px;
        flex: 1;
        text-align: left;
        .tel {
          margin: 12px 0;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }
        .info {
          margin: 2.5px 0 12px;
          color: #666;
          // 2行不换行
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
        }
      }
      // 右
      .right {
        width: 25px;
        height: 25px;
        background: url("http://yanxuan-static.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/address-right-596d39df1e.png")
          no-repeat;
        background-size: 100% 100%;
        margin: 0 10px;
      }
    }
  }
  // 请选择收货地址
  .none {
    background: url("http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/address-bg-bd30f2bfeb.png")
      repeat-x;
    padding: 25px 0 15px;
    margin-bottom: 10px;
    background-color: #fff;
    height: 65.6px;
    line-height: 65.6px;
  }
  // 信息
  .info {
    padding: 0 15px;
    background-color: #fff;
    .item {
      padding: 15px 0;
      display: flex;
      justify-content: space-between;
      border-bottom: 1px solid #d9d9d9;
    }
  }
  // 列表
  .list {
    background: #fff;
    margin: 10px auto 55px;
    .item {
      padding: 10px 0;
      border-bottom: 1px solid #f4f4f4;
      display: flex;
      align-items: center;
      justify-content: space-between;
      .left {
        display: flex;
        align-items: center;
        width: 80%;
        img {
          height: 62.5px;
          width: 62.5px;
          display: block;
          background: #f4f4f4;
          margin-left: 10px;
        }
        .info {
          width: 50%;
          padding: 10px;
          text-align: left;
          .name {
            margin: 12px 0;
            line-height: 20px;
          }
          .price {
            margin-bottom: 12px;
            line-height: 20px;
          }
        }
      }
      .right {
        padding-right: 25px;
      }
    }
  }
  // 支付
  .bottom {
    position: fixed;
    left: 0;
    bottom: 0;
    height: 50px;
    width: 100%;
    display: flex;
    background: #fff;
    .total {
      flex: 1;
      line-height: 50px;
      padding-left: 10px;
      text-align: left;
    }
    .pay {
      width: 100px;
      height: 50px;
      text-align: center;
      line-height: 50px;
      font-size: 14px;
      background: #b4282d;
      color: #fff;
    }
  }
}
</style>